package com.coocaa.x.service.litecontent.providers.apps;

import com.coocaa.x.app.framework.data.XMLParser;
import com.coocaa.x.framework.utils.LogUtils;
import com.coocaa.x.service.XServiceManager;
import com.coocaa.x.service.litecontent.data.apps.com_coocaa_app.AppData;
import com.coocaa.x.service.litecontent.providers.apps.controller.AppLastStartTimesDataController;
import com.coocaa.x.service.litecontent.providers.apps.controller.AppStartTimesDataController;
import com.coocaa.x.service.litecontent.providers.apps.data.MyAppModel;
import com.coocaa.x.service.litedb.data.client.LiteDBSupport;
import com.skyworth.badsdk.SkyAppsClassifyProperties;
import com.skyworth.framework.skysdk.properties.SkyAppsProperties;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class LocalApps {
    private static final String STOREPACKAGE = "com.tianci.appstore";
    private static final String LAUNCHERCALSS = "com.coocaa.launcher.EasyLauncherActivity";
    private static final String GAMECLASS = "com.coocaa.app.gamecenter.pages.home.GameMainActivity";
    private static final String APPSTORECALSS = "com.tianci.appstore.AppStoreActivity";
    private HashMap<String, Boolean> mAppMap = null;
    private HashMap<String, Boolean> nonDeleteMap = null;
    private HashMap<String, Boolean> androidAppMap = null;
    private HashMap<String, Integer> lastAppStartTimesMap = new HashMap<String, Integer>();
    private HashMap<String, Integer> allAppStartTimesMap = new HashMap<String, Integer>();
    private static boolean isAppConfigExit = isappconfigExit();
    private static LocalApps instance = new LocalApps();
    private static final String NONDELETECONFIG = "system/pcfg/config/recovery_nondel_dataapp.xml";
    private static final String NONDELETECONFIG2 = "system/pcfg/config/product/recovery_nondel_dataapp.xml";

    private HashSet<String> mSysSet = new HashSet<String>();
    private List<String> mAppClassifyDatas = null;
    private List<String> mChildAppPkgs = null;
    //    private List<SkyListAppData> mChildApps = null;
    private HashSet<String> mClassifySet = new HashSet<String>();
    private static final long APPMODEL_UPDATE = 7*24*60*60;  //以秒为单位

    // 测试路径
    // private static final String NONDELETECONFIG = "skydir/config/recovery_nondel_dataapp.xml";
    // private static final String NONDELETECONFIG2 =
    // "skydir/config/product/recovery_nondel_dataapp.xml";

    private static final String[] launcherAppArray = {"com.tianci.movieplatform",
            "com.tianci.appstore", "com.tianci.localmedia"};

    public static LocalApps getInstance() {
        return instance;
    }


    private LocalApps() {
        isAppConfigExit = isappconfigExit();
        getAppConfigData();
        getAppClassifyData();
    }

    private void getAppConfigData() {
        LogUtils.d("app", "getAppConfigData   isAppConfigExit:" + isAppConfigExit);
        if (isAppConfigExit) {
            if (mAppMap != null && mAppMap.size() > 0)
                return;
            mAppMap = new HashMap<String, Boolean>();
            List<String> appDatas = new ArrayList<String>();
            appDatas = SkyAppsProperties.getPropertyList();
            for (final String pkg : appDatas) {
                String prop = SkyAppsProperties.getProperty(pkg);
                if (prop.contains("myapp")) {
                    LogUtils.d("app", "getAppConfigData   pkg:" + pkg);
                    mAppMap.put(pkg, true);
                } else {
                    if (pkg.equals("com.tianci.movieplatform")
                            || pkg.equals("com.tianci.localmedia")) // 本地媒体 影视中心没有设置为myapp
                    {
                        mAppMap.put(pkg, true);
                    }
                }
            }
        } else {
            if (androidAppMap == null || androidAppMap.size() < 1) {
                androidAppMap = new HashMap<String, Boolean>();
                Map<String, String> map = XMLParser.getAndroidAppConfig();
                if (map != null && map.keySet() != null && map.size() > 0) {
                    for (String pkg : map.keySet()) {
                        if (map.get(pkg).contains("android")) {
                            LogUtils.d("app", "androidAppMap pkg:" + pkg);
                            androidAppMap.put(pkg, true);
                        }
                        // if(map.get(pkg).contains("top"))
                        // {
                        // LogUtils.d("app", "top pkg:"+pkg);
                        // }
                    }
                }
            }

            if (nonDeleteMap == null || nonDeleteMap.size() < 1) {
                nonDeleteMap = new HashMap<String, Boolean>();
                for (int i = 0; i < 2; i++) {
                    String filePath = "";
                    if (i == 0)
                        filePath = NONDELETECONFIG;
                    if (i == 1)
                        filePath = NONDELETECONFIG2;
                    Map<String, String> map = XMLParser.getNonDeleteAppConfig(filePath);
                    if (map != null && map.keySet() != null && map.size() > 0) {
                        for (String pkg : map.keySet()) {
                            // if (map.get(pkg).contains("show"))
                            // {
                            LogUtils.d("app", "nonDeleteMap pkg:" + pkg);
                            nonDeleteMap.put(pkg, true);
                            // }
                        }
                    }
                }
            }
        }
    }

    private void getAppClassifyData() {
        if (mAppClassifyDatas == null) {
            mAppClassifyDatas = SkyAppsClassifyProperties.getPropertyList();
            if (mAppClassifyDatas != null && mAppClassifyDatas.size() > 0) {
                mChildAppPkgs = new ArrayList<String>();
                for (String pkg : mAppClassifyDatas) {
                    mClassifySet.add(pkg);
                    String prop = SkyAppsClassifyProperties.getProperty(pkg);
                    if (prop.contains("child")) {
                        mChildAppPkgs.add(pkg);
                    }
                }
            }
        }
    }

    private HashSet<String> getClassifyPkg() {
        getAppClassifyData();
        return mClassifySet;
    }

    private List<String> getChildAppPkg() {
        getAppClassifyData();
        return mChildAppPkgs;
    }

    public List<AppData> filterAppList(List<AppData> list) {
        List<AppData> appList = new ArrayList<AppData>();
        List<String> A43ChildPkgs = getChildAppPkg();
        LogUtils.d("app", "filterAppList 000 list size:" + list.size() + " " + isAppConfigExit);
        for (AppData info : list) {
//            LogUtils.d("app", "filterAppList pkg:"+info.info.pkgName+"  isSystem:"+info.info.isSystemApp);
            if (info.info.isSystemApp) {
                if (isAppConfigExit) {
                    boolean addflag = false;
                    if (mAppMap.containsKey(info.info.pkgName))
                        addflag = true;
                    if (A43ChildPkgs != null && A43ChildPkgs.contains(info.info.pkgName)) {
                        addflag = false;
                    }
                    if (info.info.pkgName.equals("com.tianci.appstore")) {
                        addflag = true;
                    }
                    if (info.info.pkgName.equals("com.tianci.movieplatform"))   //4.x的版本需要过滤影视中心
                    {
                        addflag = false;
                    }
                    if (addflag) {
                        LogUtils.d("app", "filterAppList add info pkg:" + info.info.pkgName);
                        appList.add(info);
                    }
                } else {
                    if (!androidAppMap.containsKey(info.info.pkgName)) {
                        if (A43ChildPkgs != null && A43ChildPkgs.contains(info.info.pkgName)) {
                            // 不做任何事
                        } else {
                            appList.add(info);
                        }
                    }
                }
            } else {
                if (A43ChildPkgs != null && A43ChildPkgs.contains(info.info.pkgName)) {
                    // 不做任何事
                } else {
                    LogUtils.d("app", "filterAppList add info  not system  pkg:" + info.info.pkgName);
                    appList.add(info);
                }
            }
        }
        LogUtils.d("app", "filterAppList  appList size:" + appList.size());
        return appList;
    }

    public List<AppData> filterAppListForModel(List<AppData> list,String model)
    {
        List<LiteDBSupport> supportList = getAppModel(list);
        if(model.equals("model_childer"))
        {
            return getAppDataByModle(list,gPkgSet(supportList,new int[]{1,3,5,7}));
        }
        else if(model.equals("model_adults")){
            return getAppDataByModle(list,gPkgSet(supportList,new int[]{2,3,6,7}));
        }
        else if(model.equals("model_older")){
            return getAppDataByModle(list,gPkgSet(supportList,new int[]{4,5,6,7}));
        }
        return null;
    }

    private List<LiteDBSupport> getAppModel(List<AppData> list) {
        try {
            long time = XServiceManager.getLiteConfigService().getLongValue("myappmodel_update", 0);
            long curTime = System.currentTimeMillis() / 1000;
            MyAppModel db = new MyAppModel();
            if (curTime - time >= APPMODEL_UPDATE) {
                XServiceManager.getLiteConfigService().saveLongConfig("myappmodel_update", curTime);
                Map<String, Integer> map = null;
//                Map<String,Integer> map = CoocaaApplication.getCoocaaWebService().getAppStoreService().  list.size
                if(map != null && map.size() > 0)
                {
                    try {
                        MyAppModel app = new MyAppModel();
                        app.deleteAll();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    for(String pkg : map.keySet())
                    {
                        int model = map.get(pkg);
                        try {
                            MyAppModel app = new MyAppModel();
                            app.pkg = pkg;
                            app.model = model;
                            app.insert();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                return db.selectAll();
            } else {
                List<LiteDBSupport> dbList = db.selectAll();
                if (dbList != null && dbList.size() > 0 && list.size() > 0) {
                    List<AppData> tempList = new ArrayList<AppData>();
                    for (AppData data : list) {
                        for (LiteDBSupport support : dbList) {
                            MyAppModel model = (MyAppModel) support;
                            if (data.info.pkgName.equals(model.pkg)) {
                                tempList.add(data);
                                continue;
                            }
                        }
                    }
                    list.removeAll(tempList);
                }
                if (list.size() > 0) {
                    Map<String, Integer> map = null;
//                Map<String,Integer> map = CoocaaApplication.getCoocaaWebService().getAppStoreService().  list.size
                    if(map != null && map.size() > 0)
                    {
                        for(String pkg : map.keySet())
                        {
                            int model = map.get(pkg);
                            try {
                                MyAppModel app = new MyAppModel();
                                app.pkg = pkg;
                                app.model = model;
                                app.insert();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
                return db.selectAll();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private Set<String> gPkgSet(List<LiteDBSupport> supportList,int[] model){
        Set<String> pkgSet = new HashSet<String>();
        for(LiteDBSupport db:supportList){
            MyAppModel appModle = (MyAppModel)db;
            for(Integer i : model) {
                if (appModle.model == i){
                    pkgSet.add(appModle.pkg);
                    continue;
                }
            }
        }
        return pkgSet;
    }

    private List<AppData> getAppDataByModle(List<AppData> list,Set<String> set){
        List<AppData> tList = new ArrayList<AppData>();
        for(AppData data:list){
            if(set.contains(data.info.pkgName)){
                tList.add(data);
            }
        }
        return tList;
    }

    public List<AppData> filterAppListForDelete(List<AppData> list) {
//        for (AppData app : list)
//        {
//            LogUtils.d("YYY", "app:" + app.info.appName);
//        }

        List<AppData> appList = new ArrayList<AppData>();
        for (AppData info : list) {
            // LogUtils.d("localapp",
            // "filterAppListForDelete   pkg:"+info.pkgName+" isSystem:"+info.isSystemApp);
            if (info.info.isSystemApp) {
                // 系统应用升级后呈现的是data/data下的非系统应用
            } else {
                if (isAppConfigExit) {
                    boolean addflag = false;
                    if (mAppMap.containsKey(info.info.pkgName))
                        addflag = true;
                    if (info.info.pkgName.equals("com.tianci.appstore")) {
                        addflag = true;
                    }
                    if (!addflag) {
                        appList.add(info);
                    }
                } else {
                    if (!nonDeleteMap.containsKey(info.info.pkgName)
                            && !info.info.pkgName.equals("com.tianci.appstore"))
                        appList.add(info);
                }
            }
        }
        LogUtils.d("localapp", "filterAppListForDelete   size:" + appList.size());
        return appList;
    }

    public List<AppData> filterAppListForAutoStart(List<AppData> list) {
        List<AppData> appList = new ArrayList<AppData>();
        List<String> A43ChildPkgs = getChildAppPkg();
        LogUtils.d("app", "filterAppList  list size:" + list.size());
        for (AppData info : list) {
            if (info.info.isSystemApp) {
                if (isAppConfigExit) {
                    boolean addflag = false;
                    if (mAppMap.containsKey(info.info.pkgName))
                        addflag = true;
                    if (A43ChildPkgs != null && A43ChildPkgs.contains(info.info.pkgName)) {
                        addflag = false;
                    }
                    if (info.info.pkgName.equals("com.tianci.appstore")) {
                        addflag = true;
                    }
                    if (info.info.pkgName.equals("com.tianci.movieplatform"))   //4.x的版本需要过滤影视中心
                    {
                        addflag = false;
                    }
                    if (addflag) {
                        appList.add(info);
                    }
                } else {
                    if (!androidAppMap.containsKey(info.info.pkgName)) {
                        if (A43ChildPkgs != null && A43ChildPkgs.contains(info.info.pkgName)) {
                            // 不做任何事
                        } else {
                            appList.add(info);
                        }
                    }
                }
            } else {
                if (A43ChildPkgs != null && A43ChildPkgs.contains(info.info.pkgName)) {
                    // 不做任何事
                } else {
                    appList.add(info);
                }
            }
        }
        LogUtils.d("app", "filterAppList  appList size:" + appList.size());
        return appList;
    }

    public List<AppData> orderAppByInstalledTime(List<AppData> list) {
        if (list == null || list.size() < 1) {
            return new ArrayList<AppData>();
        } else {
            try {
                Collections.sort(list, new Comparator<AppData>() {
                    public int compare(AppData arg0, AppData arg1) {
                        return arg0.info.firstInstallTime > arg1.info.firstInstallTime ? -1 : 1;
                    }
                });
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    public List<AppData> orderAppByUsedTimes(List<AppData> list) {
        synchronized (this) {
            if (list == null || list.size() < 1) {
                return new ArrayList<AppData>();
            } else {
                try {
                    Collections.sort(list, new Comparator<AppData>() {
                        public int compare(AppData arg0, AppData arg1) {
                            return arg0.usedTimes > arg1.usedTimes ? -1 : 1;
                        }
                    });
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
            return list;
        }
    }

    public List<AppData> orderAppByNBWay(List<AppData> list) {
        synchronized (list) {
            List<AppData> localAllApps = new ArrayList<AppData>();
            List<AppData> anotherAppList = new ArrayList<AppData>();
            lastAppStartTimesMap = AppLastStartTimesDataController.getInstance()
                    .getLastAppStartTimesMap();
            allAppStartTimesMap = AppStartTimesDataController.getInstance()
                    .getAllAppStartTimesMap();
            for (AppData info : list) {
                String mainActivity = info.info.mainActivity;
                if (lastAppStartTimesMap.containsKey(info.info.pkgName)) {
                    info.recentlyUsedTimes = lastAppStartTimesMap.get(info.info.pkgName);
                    localAllApps.add(info);
                } else if (mainActivity.equals(APPSTORECALSS)) {
                    LogUtils.d("app", "this is appstore!!");
                    info.recentlyUsedTimes = 10000;
                    localAllApps.add(info);
                } else if (mainActivity.equals(GAMECLASS)) {
                    LogUtils.d("app", "this is game center!!");
                    info.recentlyUsedTimes = 9500;
                    localAllApps.add(info);
                } else {
                    if (allAppStartTimesMap.containsKey(info.info.pkgName)) {
                        info.usedTimes = allAppStartTimesMap.get(info.info.pkgName);
                    } else {
                        info.usedTimes = 0;
                    }
                    anotherAppList.add(info);
                }
            }

            if (localAllApps == null || localAllApps.size() < 1) {
                // return new ArrayList<SkyAppBaseData>();
            } else {
                LogUtils.d("app", "getInstalledAppByNBWAY localAllApps.size:" + localAllApps.size());
                try {
                    Collections.sort(localAllApps, new Comparator<AppData>() {
                        public int compare(AppData arg0, AppData arg1) {
                            int arg0_recentlyUsedTimes = arg0.recentlyUsedTimes, arg1_recentlyUsedTimes = arg1.recentlyUsedTimes;
                            if (arg0_recentlyUsedTimes > 0 && arg1_recentlyUsedTimes > 0) {
                                arg0_recentlyUsedTimes = arg0_recentlyUsedTimes / 3;
                                arg1_recentlyUsedTimes = arg1_recentlyUsedTimes / 3;
                            }

                            return (arg1_recentlyUsedTimes - arg0_recentlyUsedTimes);
                        }
                    });
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }

            if (anotherAppList == null || anotherAppList.size() < 1) {
                // return new ArrayList<SkyAppBaseData>();
            } else {
                LogUtils.d("app", "getInstalledAppByNBWAY anotherAppList.size:" + anotherAppList.size());
                try {
                    Collections.sort(anotherAppList, new Comparator<AppData>() {
                        public int compare(AppData arg0, AppData arg1) {

                            return arg0.usedTimes > arg1.usedTimes ? -1 : 1;
                        }
                    });
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
            localAllApps.addAll(anotherAppList);
            LogUtils.d("app", "getInstalledAppByNBWAY AllApps.size:" + localAllApps.size());
            return localAllApps;
        }
    }

    public List<AppData> orderAppForLauncherPick(List<AppData> list) {
        List<String> pkgList = Arrays.asList(launcherAppArray);
        if (list.size() > 0) {
            Map<String, AppData> appMap = new HashMap<String, AppData>();
            for (AppData info : list) {
                appMap.put(info.info.pkgName, info);
            }
            int loc = 0;
            for (String pkg : pkgList) {
                if (appMap.keySet().contains(pkg)) {
                    LogUtils.d("app", "orderAppForLauncher  loc  pkg:" + loc + " " + pkg);
                    AppData temp = appMap.get(pkg);
                    list.remove(appMap.get(pkg));
                    list.add(loc, temp);
                    loc++;
                }
            }
        }
        return list;
    }

    public List<AppData> orderAppForLauncherAll(List<AppData> list) {
        return list;
    }

    public List<AppData> orderAppForMine(List<AppData> list) {
        //先在这里实现我的应用屏蔽影视中心、本地媒体，后续再改成配置文件方式
        if (list.size() > 0) {
            List<AppData> aa = new ArrayList<AppData>();
            for (AppData data : list) {
                if (data.info.pkgName.equals("com.tianci.localmedia") || data.info.pkgName.equals("com.tianci.movieplatform"))
                    aa.add(data);
            }
            for (AppData d : aa)
                list.remove(d);
        }
        return list;
//        List<AppData> appList = new ArrayList<AppData>();
//        boolean isLauncherShow = true;
//        boolean isGameShow = true;
//        String launcher_entry = SkyGeneralProperties.getProperty("x_launcher_entry");
//        if (launcher_entry != null)
//        {
//            isLauncherShow = Boolean.parseBoolean(launcher_entry);
//        } else
//        {
//            isLauncherShow = true;
//        }
//        String gamecenter_entry = SkyGeneralProperties.getProperty("x_gamecenter_entry");
//        if (gamecenter_entry != null)
//        {
//            isGameShow = Boolean.parseBoolean(gamecenter_entry);
//        } else
//        {
//            isGameShow = true;
//        }
//        LogUtils.d("show", "isLauncherShow:" + isLauncherShow + " isGameShow:" + isGameShow);
//        if (list != null && list.size() > 0)
//        {
//            LogUtils.d("app", "orderAppForMine 000  size:" + list.size());
//            synchronized (list)
//            {
//                for (AppData info : list)
//                {
//                    LogUtils.d("app", "orderAppForMine 22222222 pkg:" + info.info.pkgName);
//                    if (info.info.activityList != null && info.info.activityList.size() > 1)
//                    {
//                        List<MActivityInfo> mList = info.info.activityList;
//                        for (MActivityInfo aInfo : mList)
//                        {
//                            if (!aInfo.className.equals(APPSTORECALSS))
//                            {
//                                if (aInfo.className.equals(LAUNCHERCALSS))
//                                {
//                                    if (isLauncherShow)
//                                        appList.add(0, info);
//                                } else if (aInfo.className.equals(GAMECLASS))
//                                {
//                                    if (isGameShow)
//                                    {
//                                        if (appList.size() == 0)
//                                        {
//                                            appList.add(0, info);
//                                        } else
//                                        {
//                                            boolean contain_game = false;
//                                            for (AppData data : appList)
//                                            {
//                                                String pkg = data.info.pkgName;
//                                                if (pkg.contains(STOREPACKAGE))
//                                                {
//                                                    contain_game = true;
//                                                }
//                                            }
//                                            if (contain_game)
//                                                appList.add(1, info);
//                                            else
//                                                appList.add(0, info);
//                                        }
//                                    }
//                                } else
//                                    appList.add(info);
//                            }
//                        }
//                    } else
//                    {
//                        appList.add(info);
//                    }
//                }
//            }
//        }
//        LogUtils.d("app", "orderAppForMine   size:" + appList.size());
//        return appList;
    }

    public List<AppData> orderAppForDelete(List<AppData> list) {
        return list;
    }

    public List<AppData> orderAppForGame(List<AppData> list) {
        return list;
    }

    public List<AppData> orderAppForAutoStart(List<AppData> list) {
        return list;
    }

//    public AppStatus getInstallAppStatus(String pkg,int versionName)
//    {
//        List<AppData> applist = LocalAppManager.getInstance().getInstalledAppList();
//        if (applist != null && applist.size() > 0)
//        {
//            for (int i = 0; i < applist.size(); i++)
//            {
//                String pkg1 = applist.get(i).info.pkgName;
//                int versionName1 = applist.get(i).info.versionCode;
//                if (pkg.equals(pkg1))
//                {
//                    if (versionName > versionName1)
//                        return AppStatus.HAS_NEW_VERSION;
//                    else
//                        return AppStatus.INSTALLED;
//                }
//            }
//        }
//        return AppStatus.NOT_DOWNLOADED;
//    }

    public List<String> getUnexitAppList(List<String> pkgList) {
        List<String> list = new ArrayList<String>();
        if (pkgList != null && pkgList.size() > 0) {
            List<AppData> applist = LocalAppManager.getInstance().getInstalledAppList();
            if (applist != null && applist.size() > 0) {
                for (String pkg : pkgList) {
                    boolean exit = false;
                    for (int i = 0; i < applist.size(); i++) {
                        if (pkg.equals(applist.get(i).info.pkgName)) {
                            exit = true;
                            break;
                        }
                    }
                    if (!exit) {
                        list.add(pkg);
                    }
                }
            }
        }
        return list;
    }

//    public List<SkyListAppData> getListAppDataFromAppInfo(List<AppData> list)
//    {
//        List<SkyListAppData> appList = new ArrayList<SkyListAppData>();
//        if (list != null && list.size() > 0)
//        {
//            for (AppData info : list)
//            {
//                SkyListAppData AppData = new SkyListAppData(ListType.LOCAL_APP_LIST, "",
//                        info.appName, "", info.pkgName);
//                AppData.setVersionName(String.valueOf(info.versionCode));
//                AppData.setMainActivity(info.mainActivity);
//                // LogUtils.d("localapp", "getLocalAppsForMainPage--" + info.pkgName + " "
//                // + info.usedTimes);
//                long size = info.size / SkyConstants.BTOK;
//                AppData.setSize(size);
//                float size2 = (float) size / SkyConstants.KTOM;
//                if (size2 > 1.0f)
//                {
//                    size2 = Tools.fixFloat(size2);
//                    AppData.setShowInfo(String.valueOf(size2) + "MB");
//                } else
//                {
//                    AppData.setShowInfo(String.valueOf(size) + "KB");
//                }
//                if (!info.pkgName.equals("") && !info.pkgName.equals(STOREPACKAGE))
//                    appList.add(AppData);
//            }
//        }
//        LogUtils.d("localapp", "getListAppDataFromAppInfo   size:" + appList.size());
//        return appList;
//    }

//    public List<SkyAppBaseData> getBaseDataFromAppInfo(List<AppData> list)
//    {
//        List<SkyAppBaseData> appList = new ArrayList<SkyAppBaseData>();
//        boolean isLauncherShow = true;
//        boolean isGameShow = true;
//        String launcher_entry = SkyGeneralProperties.getProperty("x_launcher_entry");
//        if (launcher_entry != null)
//        {
//            isLauncherShow = Boolean.parseBoolean(launcher_entry);
//        } else
//        {
//            isLauncherShow = true;
//        }
//        String gamecenter_entry = SkyGeneralProperties.getProperty("x_gamecenter_entry");
//        if (gamecenter_entry != null)
//        {
//            isGameShow = Boolean.parseBoolean(gamecenter_entry);
//        } else
//        {
//            isGameShow = true;
//        }
//        LogUtils.d("show", "isLauncherShow:" + isLauncherShow + " isGameShow:" + isGameShow);
//        if (list != null && list.size() > 0)
//        {
//            synchronized (list)
//            {
//                for (AppData info : list)
//                {
//                    // LogUtils.d("localapp",
//                    // "getBaseDataFromAppInfo pkg:"+info.pkgName+" size:"+info.activityList.size());
//                    if (info.activityList != null && info.activityList.size() > 1)
//                    {
//                        List<MActivityInfo> mList = info.activityList;
//                        for (MActivityInfo aInfo : mList)
//                        {
//                            SkyListAppData AppData = new SkyListAppData(ListType.LOCAL_APP_LIST,
//                                    "", aInfo.name, "", info.pkgName);
//                            AppData.setVersionName(String.valueOf(info.versionCode));
//                            AppData.setInstallTime(info.firstInstallTime);
//                            AppData.setMainActivity(aInfo.className);
//                            AppData.setPackageName(info.pkgName);
//                            if (!aInfo.className.equals(AppStoreActivity.class.getName()))
//                            {
//                                if (aInfo.className.equals(EasyLauncherActivity.class.getName()))
//                                {
//                                    if (isLauncherShow)
//                                        appList.add(0, AppData);
//                                } else if (aInfo.className.equals(GameMainActivity.class.getName()))
//                                {
//                                    if (isGameShow)
//                                    {
//                                        if (appList.size() == 0)
//                                        {
//                                            appList.add(0, AppData);
//                                        } else
//                                        {
//                                            boolean contain_game = false;
//                                            for (SkyAppBaseData data : appList)
//                                            {
//                                                String pkg = ((SkyListAppData) data).getPkgName();
//                                                if (pkg.contains(STOREPACKAGE))
//                                                {
//                                                    contain_game = true;
//                                                }
//                                            }
//                                            if (contain_game)
//                                                appList.add(1, AppData);
//                                            else
//                                                appList.add(0, AppData);
//                                        }
//                                    }
//                                } else
//                                    appList.add(AppData);
//                            }
//                        }
//                    } else
//                    {
//                        SkyListAppData AppData = new SkyListAppData(ListType.LOCAL_APP_LIST, "",
//                                info.appName, "", info.pkgName);
//                        AppData.setVersionName(String.valueOf(info.versionCode));
//                        AppData.setInstallTime(info.firstInstallTime);
//                        AppData.setMainActivity(info.mainActivity);
//                        AppData.setPackageName(info.pkgName);
//                        // if (!info.mainActivity.equals(AppStoreActivity.class.getName()))
//                        appList.add(AppData);
//                    }
//                }
//            }
//        }
//        LogUtils.d("localapp", "getBaseDataFromAppInfo   size:" + appList.size());
//        return appList;
//    }

    private static boolean isappconfigExit() {
        File file = new File("/skydir/config/app_config.xml");
        if (file.exists())
            return true;
        else
            return false;
    }

    public boolean isNoDeleteApp(String pkg)
    {
        if (nonDeleteMap != null && nonDeleteMap.containsKey(pkg))
            return true;
        return false;
    }
}
